<?php
/**
 * /depot/library/models/Config/Table.php
 * @author qqinxl
 * 2008/03/24
 * 
 * @category  
 * @package  
 * @copyright  Copyright (c) {}
 */
class Config_Table {
	const DEFAULT_NULL_VALUE = '-----';
	
	const TABLE_USER = 'dev_users';
	const TABLE_USER_ALBUM = 'dev_user_album';
	const TABLE_USER_ALBUM_CATEGORY = 'dev_user_album_categories';
	
	const TABLE_ACL_ROLE = 'dev_user_acl_roles';
	const TABLE_ACL_RESOURCE = 'dev_user_acl_resources';
	
	const TABLE_BLOG = 'dev_blogs';
	const TABLE_BLOG_CATEGORY = 'dev_blog_categories';
	const TABLE_BLOG_REMARK = 'dev_blog_remarks';
	const TABLE_BLOG_TAG = 'dev_blog_tags';
	const TABLE_BLOG_TAG_RELATION = 'dev_blog_tag_relations';
	
	
	
	static public function getFields($tablename) {		
		$_cache = null;
		if (Zend_Registry::isRegistered ( 'cache' )) {
			$_cache = Zend_Registry::get ( 'cache' );
		}
		$id = 'table_' . $tablename . '_info';
		if (! empty ( $_cache ) and $_cache instanceof Zend_Cache_Core) {
			$data = $_cache->load ( $id );
		}
		if (empty ( $data )) {			
			$data = Zend_Db_Table::getDefaultAdapter()->describeTable ( $tablename );
			if (! empty ( $_cache ) and $_cache instanceof Zend_Cache_Core) {
				$_cache->save ( $data, $id );
			}			
		}
		return $data;
	}
	
	static public function getInfo($info,$tablename){
		$tableinfo = array_keys(self::getFields($tablename));
		$_info = array();
		foreach ($tableinfo as $key){
			if(isset($info[$key])){
				$value = trim($info[$key]);
				if($value == self::DEFAULT_NULL_VALUE){
					$value = null;
				}
				$_info[$key] = $value;
			}
		}
		return $_info;		
	}

}